import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  ClassSerializerInterceptor,
  UseInterceptors,
  UseGuards,
} from '@nestjs/common';
import { StudentCourseService } from './student-course.service';
import { CreateStudentCourseDto } from './dto/create-student-course.dto';
import { UpdateStudentCourseDto } from './dto/update-student-course.dto';
import {
  ApiBody,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { JwtGuard } from '../guards/jwt.guards';

@Controller('student-course')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(JwtGuard) // 校验token是否通过
@ApiTags('学生选课模块')
export class StudentCourseController {
  constructor(private readonly studentCourseService: StudentCourseService) {}

  @Post()
  @ApiOperation({ summary: '学生选课' })
  @ApiBody({ type: CreateStudentCourseDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateStudentCourseDto,
  })
  create(@Body() createStudentCourseDto: CreateStudentCourseDto) {
    return this.studentCourseService.create(createStudentCourseDto);
  }

  @Get(':id')
  @ApiOperation({ summary: '学生选课详情' })
  @ApiQuery({ name: 'id', required: true, description: '学生d' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: [CreateStudentCourseDto],
  })
  find(@Param('id') id: number) {
    return this.studentCourseService.findOne(id);
  }

  @Delete(':id')
  @ApiOperation({ summary: '学生退课' })
  @ApiQuery({ name: 'id', required: true, description: '课程id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateStudentCourseDto,
  })
  remove(@Param('id') id: number) {
    return this.studentCourseService.remove(id);
  }
}
